package com.iwuke.dance.wallet.starlight_value.adapter;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.iwuke.dance.R;
import com.iwuke.dance.util.GlideUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.wallet.starlight_value.BalanceDetailsActivity;
import com.iwuke.dance.wallet.starlight_value.EventDetailsActivity;
import com.iwuke.dance.wallet.starlight_value.LiveDetailsActivity;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;

import java.io.Serializable;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * @author: 魏从响
 * @date: 2025/9/18
 */
public class StarlightValueDetailsAdapter extends BaseQuickAdapter<StarlightTransactionRecordHomepageBean, BaseViewHolder> {
    private final Context context;

    public StarlightValueDetailsAdapter(Context context, int adapterStarlightValueDetails, List<StarlightTransactionRecordHomepageBean> lists) {
        super(adapterStarlightValueDetails, lists);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, StarlightTransactionRecordHomepageBean s) {

        RelativeLayout rlt_starlight_value_details = baseViewHolder.findView(R.id.rlt_starlight_value_details);
        ImageView img_avatar = baseViewHolder.findView(R.id.img_avatar);//图片
        TextView tv_item_title = baseViewHolder.findView(R.id.tv_item_title);//条目标题
        TextView tv_starlight_value = baseViewHolder.findView(R.id.tv_starlight_value);//星光值
        TextView tv_item_time = baseViewHolder.findView(R.id.tv_item_time);//时间
        TextView tv_balance = baseViewHolder.findView(R.id.tv_balance);//余额

        if (!TextUtils.isEmpty(s.iconUrl)){
            GlideUtil.setImageView(context,s.iconUrl,img_avatar);//头像
        }else {

            //交易子类型：1.1-微信充值，2.1-提现到微信，2.2-提现到余额，3.1-送礼物，4.1-消费，5.1-收到礼物，6.1-直播收入
            switch (s.txnSubType){
                case "2.1":
                    GlideUtil.setImageView(context,R.mipmap.img_wechat,img_avatar);
                    break;

                case "6.1"://直播收入
                    GlideUtil.setImageView(context,R.mipmap.img_event,img_avatar);
                    break;

                case "6.2"://活动收益
                    GlideUtil.setImageView(context,R.mipmap.img_live,img_avatar);
                    break;

            }

        }

        tv_item_title.setText(s.remark);//给主播赠送了小心心  标题 星光值页面

        switch (s.txnType){
            case 1:
                //支出
                tv_starlight_value.setText("-"+s.amount);//-1
                tv_starlight_value.setTextColor(context.getColor(R.color.color_000));
                break;

            case 2:
                //收入
                tv_starlight_value.setText("+"+s.amount);//+1
                tv_starlight_value.setTextColor(context.getColor(R.color.color_f0));
                break;
        }
//        tv_starlight_value.setText(String.valueOf(s.totalPrice));//收益
        tv_item_time.setText(s.createTime);//时间
        tv_balance.setText("余额："+s.starlightBalanceAfter);

        rlt_starlight_value_details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("data", (Serializable)s);
                if (s.txnSubType.equals("6.1")){//直播收入
                    Util.setIntent(context, LiveDetailsActivity.class,bundle);
                }else if (s.txnSubType.equals("6.2")){//活动收益
                    Util.setIntent(context, EventDetailsActivity.class,bundle);
                }else if (s.txnSubType.equals("2.1")){//提现到微信
                    Util.setIntent(context, BalanceDetailsActivity.class,bundle);
                }
            }
        });


    }
}
